#include "stdafx.h"
#include "net/HTTPSessionInstantiator.hpp"
#include "net/HTTPSessionFactory.hpp"
#include "net/HTTPClientSession.hpp"

NET_NAMESPACE_BEGIN

CHTTPSessionInstantiator::CHTTPSessionInstantiator() : m_proxyPort(0)
{
}

CHTTPSessionInstantiator::~CHTTPSessionInstantiator()
{
}

CHTTPClientSession* CHTTPSessionInstantiator::createClientSession(const CURI& uri)
{
	jh_assert (uri.getScheme() == "http");
	CHTTPClientSession* pSession = new CHTTPClientSession(uri.getHost(), uri.getPort());
	pSession->setProxy(proxyHost(), proxyPort());
	pSession->setProxyCredentials(proxyUsername(), proxyPassword());
	return pSession;
}

void CHTTPSessionInstantiator::registerInstantiator()
{
	CHTTPSessionFactory::defaultFactory().registerProtocol("http", new CHTTPSessionInstantiator);
}

void CHTTPSessionInstantiator::unregisterInstantiator()
{
	CHTTPSessionFactory::defaultFactory().unregisterProtocol("http");
}

void CHTTPSessionInstantiator::setProxy(const std::string& host, UInt16 port)
{
	m_proxyHost = host;
	m_proxyPort = port;
}

void CHTTPSessionInstantiator::setProxyCredentials(const std::string& username, const std::string& password)
{
	m_proxyUsername = username;
	m_proxyPassword = password;
}

const std::string& CHTTPSessionInstantiator::proxyHost() const
{
	return m_proxyHost;
}

UInt16 CHTTPSessionInstantiator::proxyPort() const
{
	return m_proxyPort;
}

const std::string& CHTTPSessionInstantiator::proxyUsername() const
{
	return m_proxyUsername;
}

const std::string& CHTTPSessionInstantiator::proxyPassword() const
{
	return m_proxyPassword;
}


NET_NAMESPACE_END
